#param ([string]$currentdir, [string]$builddestdir)

$ErrorActionPreference = "Stop"

$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
$releasedir = "Sparklings\bin\x86\Release\"

if(!(Test-Path $msbuild)){
	Write-Host "It seems that msbuild isn't at the correct place on your machine. Exiting."
	exit 1
}

cd "Sparklings"
& $msbuild "/target:publish" "/p:Configuration=Release"
if(!($LastExitCode -ne 0)){
	cd ..
	[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
	[void][System.Windows.Forms.MessageBox]::Show("Build failed. Stopping here.","Release process failed.")
	exit 1
}

cd ..

Write-Host 'Creating Codeplex zip'
$codeplexZipName = $releasedir + "upload_to_codplex.zip"
[void][Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
if (Test-Path $codeplexZipName){
	Write-Host "Removing previous version."
	Remove-Item $codeplexZipName
}

[void][System.IO.Compression.ZipFile]::CreateFromDirectory($releasedir+"app.publish",$codeplexZipName)
start-process explorer.exe -ArgumentList $releasedir
Write-Host 'Codeplex zip created'